<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - code analysis - include/caffe/sgd_solvers.hpp</title>
  <link rel="stylesheet" type="text/css" href="../../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../../index.html">top level</a> - <a href="index.html">include/caffe</a> - sgd_solvers.hpp<span style="font-size: 80%;"> (source / <a href="sgd_solvers.hpp.func-sort-c.html">functions</a>)</span></td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">code analysis</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">0</td>
            <td class="headerCovTableEntry">45</td>
            <td class="headerCovTableEntryLo">0.0 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2020-09-11 22:25:26</td>
            <td></td>
            <td class="headerItem">Functions:</td>
            <td class="headerCovTableEntry">0</td>
            <td class="headerCovTableEntry">66</td>
            <td class="headerCovTableEntryLo">0.0 %</td>
          </tr>
          <tr>
            <td class="headerItem">Legend:</td>
            <td class="headerValueLeg">            Lines:
            <span class="coverLegendCov">hit</span>
            <span class="coverLegendNoCov">not hit</span>
</td>
            <td></td>
          </tr>
          <tr><td><img src="../../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<a name="1"><span class="lineNum">       1 </span>            : #ifndef CAFFE_SGD_SOLVERS_HPP_</a>
<span class="lineNum">       2 </span>            : #define CAFFE_SGD_SOLVERS_HPP_
<span class="lineNum">       3 </span>            : 
<span class="lineNum">       4 </span>            : #include &lt;string&gt;
<span class="lineNum">       5 </span>            : #include &lt;vector&gt;
<span class="lineNum">       6 </span>            : 
<span class="lineNum">       7 </span>            : #include &quot;caffe/solver.hpp&quot;
<span class="lineNum">       8 </span>            : 
<span class="lineNum">       9 </span>            : namespace caffe {
<span class="lineNum">      10 </span>            : 
<span class="lineNum">      11 </span>            : /**
<span class="lineNum">      12 </span>            :  * @brief Optimizes the parameters of a Net using
<span class="lineNum">      13 </span>            :  *        stochastic gradient descent (SGD) with momentum.
<a name="14"><span class="lineNum">      14 </span>            :  */</a>
<span class="lineNum">      15 </span>            : template &lt;typename Dtype&gt;
<a name="16"><span class="lineNum">      16 </span><span class="lineNoCov">          0 : class SGDSolver : public Solver&lt;Dtype&gt; {</span></a>
<span class="lineNum">      17 </span>            :  public:
<a name="18"><span class="lineNum">      18 </span><span class="lineNoCov">          0 :   explicit SGDSolver(const SolverParameter&amp; param)</span></a>
<span class="lineNum">      19 </span><span class="lineNoCov">          0 :       : Solver&lt;Dtype&gt;(param) { PreSolve(); }</span>
<a name="20"><span class="lineNum">      20 </span><span class="lineNoCov">          0 :   explicit SGDSolver(const string&amp; param_file)</span></a>
<span class="lineNum">      21 </span><span class="lineNoCov">          0 :       : Solver&lt;Dtype&gt;(param_file) { PreSolve(); }</span>
<a name="22"><span class="lineNum">      22 </span><span class="lineNoCov">          0 :   virtual inline const char* type() const { return &quot;SGD&quot;; }</span></a>
<span class="lineNum">      23 </span>            : 
<span class="lineNum">      24 </span><span class="lineNoCov">          0 :   const vector&lt;shared_ptr&lt;Blob&lt;Dtype&gt; &gt; &gt;&amp; history() { return history_; }</span>
<span class="lineNum">      25 </span>            : 
<span class="lineNum">      26 </span>            :   virtual void ApplyUpdate();
<span class="lineNum">      27 </span>            :   Dtype GetLearningRate();
<span class="lineNum">      28 </span>            : 
<span class="lineNum">      29 </span>            :  protected:
<span class="lineNum">      30 </span>            :   void PreSolve();
<span class="lineNum">      31 </span>            :   virtual void Normalize(int param_id);
<span class="lineNum">      32 </span>            :   virtual void Regularize(int param_id);
<span class="lineNum">      33 </span>            :   virtual void ComputeUpdateValue(int param_id, Dtype rate);
<span class="lineNum">      34 </span>            :   virtual void ClipGradients();
<span class="lineNum">      35 </span>            :   virtual void SnapshotSolverState(const string&amp; model_filename);
<span class="lineNum">      36 </span>            :   virtual void SnapshotSolverStateToBinaryProto(const string&amp; model_filename);
<span class="lineNum">      37 </span>            :   virtual void SnapshotSolverStateToHDF5(const string&amp; model_filename);
<span class="lineNum">      38 </span>            :   virtual void RestoreSolverStateFromHDF5(const string&amp; state_file);
<span class="lineNum">      39 </span>            :   virtual void RestoreSolverStateFromBinaryProto(const string&amp; state_file);
<span class="lineNum">      40 </span>            :   // history maintains the historical momentum data.
<span class="lineNum">      41 </span>            :   // update maintains update related data and is not needed in snapshots.
<span class="lineNum">      42 </span>            :   // temp maintains other information that might be needed in computation
<span class="lineNum">      43 </span>            :   //   of gradients/updates and is not needed in snapshots
<span class="lineNum">      44 </span>            :   vector&lt;shared_ptr&lt;Blob&lt;Dtype&gt; &gt; &gt; history_, update_, temp_;
<span class="lineNum">      45 </span>            : 
<span class="lineNum">      46 </span>            :   DISABLE_COPY_AND_ASSIGN(SGDSolver);
<span class="lineNum">      47 </span>            : };
<a name="48"><span class="lineNum">      48 </span>            : </a>
<span class="lineNum">      49 </span>            : template &lt;typename Dtype&gt;
<a name="50"><span class="lineNum">      50 </span><span class="lineNoCov">          0 : class NesterovSolver : public SGDSolver&lt;Dtype&gt; {</span></a>
<span class="lineNum">      51 </span>            :  public:
<a name="52"><span class="lineNum">      52 </span><span class="lineNoCov">          0 :   explicit NesterovSolver(const SolverParameter&amp; param)</span></a>
<span class="lineNum">      53 </span><span class="lineNoCov">          0 :       : SGDSolver&lt;Dtype&gt;(param) {}</span>
<a name="54"><span class="lineNum">      54 </span><span class="lineNoCov">          0 :   explicit NesterovSolver(const string&amp; param_file)</span></a>
<span class="lineNum">      55 </span><span class="lineNoCov">          0 :       : SGDSolver&lt;Dtype&gt;(param_file) {}</span>
<span class="lineNum">      56 </span><span class="lineNoCov">          0 :   virtual inline const char* type() const { return &quot;Nesterov&quot;; }</span>
<span class="lineNum">      57 </span>            : 
<span class="lineNum">      58 </span>            :  protected:
<span class="lineNum">      59 </span>            :   virtual void ComputeUpdateValue(int param_id, Dtype rate);
<span class="lineNum">      60 </span>            : 
<span class="lineNum">      61 </span>            :   DISABLE_COPY_AND_ASSIGN(NesterovSolver);
<span class="lineNum">      62 </span>            : };
<a name="63"><span class="lineNum">      63 </span>            : </a>
<span class="lineNum">      64 </span>            : template &lt;typename Dtype&gt;
<a name="65"><span class="lineNum">      65 </span><span class="lineNoCov">          0 : class AdaGradSolver : public SGDSolver&lt;Dtype&gt; {</span></a>
<span class="lineNum">      66 </span>            :  public:
<a name="67"><span class="lineNum">      67 </span><span class="lineNoCov">          0 :   explicit AdaGradSolver(const SolverParameter&amp; param)</span></a>
<span class="lineNum">      68 </span><span class="lineNoCov">          0 :       : SGDSolver&lt;Dtype&gt;(param) { constructor_sanity_check(); }</span>
<a name="69"><span class="lineNum">      69 </span><span class="lineNoCov">          0 :   explicit AdaGradSolver(const string&amp; param_file)</span></a>
<span class="lineNum">      70 </span><span class="lineNoCov">          0 :       : SGDSolver&lt;Dtype&gt;(param_file) { constructor_sanity_check(); }</span>
<span class="lineNum">      71 </span><span class="lineNoCov">          0 :   virtual inline const char* type() const { return &quot;AdaGrad&quot;; }</span>
<span class="lineNum">      72 </span>            : 
<a name="73"><span class="lineNum">      73 </span>            :  protected:</a>
<span class="lineNum">      74 </span>            :   virtual void ComputeUpdateValue(int param_id, Dtype rate);
<span class="lineNum">      75 </span><span class="lineNoCov">          0 :   void constructor_sanity_check() {</span>
<span class="lineNum">      76 </span><span class="lineNoCov">          0 :     CHECK_EQ(0, this-&gt;param_.momentum())</span>
<span class="lineNum">      77 </span>            :         &lt;&lt; &quot;Momentum cannot be used with AdaGrad.&quot;;
<span class="lineNum">      78 </span><span class="lineNoCov">          0 :   }</span>
<span class="lineNum">      79 </span>            : 
<span class="lineNum">      80 </span>            :   DISABLE_COPY_AND_ASSIGN(AdaGradSolver);
<span class="lineNum">      81 </span>            : };
<span class="lineNum">      82 </span>            : 
<a name="83"><span class="lineNum">      83 </span>            : </a>
<span class="lineNum">      84 </span>            : template &lt;typename Dtype&gt;
<a name="85"><span class="lineNum">      85 </span><span class="lineNoCov">          0 : class RMSPropSolver : public SGDSolver&lt;Dtype&gt; {</span></a>
<span class="lineNum">      86 </span>            :  public:
<a name="87"><span class="lineNum">      87 </span><span class="lineNoCov">          0 :   explicit RMSPropSolver(const SolverParameter&amp; param)</span></a>
<span class="lineNum">      88 </span><span class="lineNoCov">          0 :       : SGDSolver&lt;Dtype&gt;(param) { constructor_sanity_check(); }</span>
<a name="89"><span class="lineNum">      89 </span><span class="lineNoCov">          0 :   explicit RMSPropSolver(const string&amp; param_file)</span></a>
<span class="lineNum">      90 </span><span class="lineNoCov">          0 :       : SGDSolver&lt;Dtype&gt;(param_file) { constructor_sanity_check(); }</span>
<span class="lineNum">      91 </span><span class="lineNoCov">          0 :   virtual inline const char* type() const { return &quot;RMSProp&quot;; }</span>
<span class="lineNum">      92 </span>            : 
<a name="93"><span class="lineNum">      93 </span>            :  protected:</a>
<span class="lineNum">      94 </span>            :   virtual void ComputeUpdateValue(int param_id, Dtype rate);
<span class="lineNum">      95 </span><span class="lineNoCov">          0 :   void constructor_sanity_check() {</span>
<span class="lineNum">      96 </span><span class="lineNoCov">          0 :     CHECK_EQ(0, this-&gt;param_.momentum())</span>
<span class="lineNum">      97 </span>            :         &lt;&lt; &quot;Momentum cannot be used with RMSProp.&quot;;
<span class="lineNum">      98 </span><span class="lineNoCov">          0 :     CHECK_GE(this-&gt;param_.rms_decay(), 0)</span>
<span class="lineNum">      99 </span>            :         &lt;&lt; &quot;rms_decay should lie between 0 and 1.&quot;;
<span class="lineNum">     100 </span><span class="lineNoCov">          0 :     CHECK_LT(this-&gt;param_.rms_decay(), 1)</span>
<span class="lineNum">     101 </span>            :         &lt;&lt; &quot;rms_decay should lie between 0 and 1.&quot;;
<span class="lineNum">     102 </span><span class="lineNoCov">          0 :   }</span>
<span class="lineNum">     103 </span>            : 
<span class="lineNum">     104 </span>            :   DISABLE_COPY_AND_ASSIGN(RMSPropSolver);
<span class="lineNum">     105 </span>            : };
<a name="106"><span class="lineNum">     106 </span>            : </a>
<span class="lineNum">     107 </span>            : template &lt;typename Dtype&gt;
<a name="108"><span class="lineNum">     108 </span><span class="lineNoCov">          0 : class AdaDeltaSolver : public SGDSolver&lt;Dtype&gt; {</span></a>
<span class="lineNum">     109 </span>            :  public:
<a name="110"><span class="lineNum">     110 </span><span class="lineNoCov">          0 :   explicit AdaDeltaSolver(const SolverParameter&amp; param)</span></a>
<span class="lineNum">     111 </span><span class="lineNoCov">          0 :       : SGDSolver&lt;Dtype&gt;(param) { AdaDeltaPreSolve(); }</span>
<a name="112"><span class="lineNum">     112 </span><span class="lineNoCov">          0 :   explicit AdaDeltaSolver(const string&amp; param_file)</span></a>
<span class="lineNum">     113 </span><span class="lineNoCov">          0 :       : SGDSolver&lt;Dtype&gt;(param_file) { AdaDeltaPreSolve(); }</span>
<span class="lineNum">     114 </span><span class="lineNoCov">          0 :   virtual inline const char* type() const { return &quot;AdaDelta&quot;; }</span>
<span class="lineNum">     115 </span>            : 
<span class="lineNum">     116 </span>            :  protected:
<span class="lineNum">     117 </span>            :   void AdaDeltaPreSolve();
<span class="lineNum">     118 </span>            :   virtual void ComputeUpdateValue(int param_id, Dtype rate);
<span class="lineNum">     119 </span>            : 
<span class="lineNum">     120 </span>            :   DISABLE_COPY_AND_ASSIGN(AdaDeltaSolver);
<span class="lineNum">     121 </span>            : };
<span class="lineNum">     122 </span>            : 
<span class="lineNum">     123 </span>            : /**
<span class="lineNum">     124 </span>            :  * @brief AdamSolver, an algorithm for first-order gradient-based optimization
<span class="lineNum">     125 </span>            :  *        of stochastic objective functions, based on adaptive estimates of
<span class="lineNum">     126 </span>            :  *        lower-order moments. Described in [1].
<span class="lineNum">     127 </span>            :  *
<span class="lineNum">     128 </span>            :  * [1] D. P. Kingma and J. L. Ba, &quot;ADAM: A Method for Stochastic Optimization.&quot;
<span class="lineNum">     129 </span>            :  *     arXiv preprint arXiv:1412.6980v8 (2014).
<a name="130"><span class="lineNum">     130 </span>            :  */</a>
<span class="lineNum">     131 </span>            : template &lt;typename Dtype&gt;
<a name="132"><span class="lineNum">     132 </span><span class="lineNoCov">          0 : class AdamSolver : public SGDSolver&lt;Dtype&gt; {</span></a>
<span class="lineNum">     133 </span>            :  public:
<a name="134"><span class="lineNum">     134 </span><span class="lineNoCov">          0 :   explicit AdamSolver(const SolverParameter&amp; param)</span></a>
<span class="lineNum">     135 </span><span class="lineNoCov">          0 :       : SGDSolver&lt;Dtype&gt;(param) { AdamPreSolve();}</span>
<a name="136"><span class="lineNum">     136 </span><span class="lineNoCov">          0 :   explicit AdamSolver(const string&amp; param_file)</span></a>
<span class="lineNum">     137 </span><span class="lineNoCov">          0 :       : SGDSolver&lt;Dtype&gt;(param_file) { AdamPreSolve(); }</span>
<span class="lineNum">     138 </span><span class="lineNoCov">          0 :   virtual inline const char* type() const { return &quot;Adam&quot;; }</span>
<span class="lineNum">     139 </span>            : 
<span class="lineNum">     140 </span>            :  protected:
<span class="lineNum">     141 </span>            :   void AdamPreSolve();
<span class="lineNum">     142 </span>            :   virtual void ComputeUpdateValue(int param_id, Dtype rate);
<span class="lineNum">     143 </span>            : 
<span class="lineNum">     144 </span>            :   DISABLE_COPY_AND_ASSIGN(AdamSolver);
<span class="lineNum">     145 </span>            : };
<span class="lineNum">     146 </span>            : 
<span class="lineNum">     147 </span>            : }  // namespace caffe
<span class="lineNum">     148 </span>            : 
<span class="lineNum">     149 </span>            : #endif  // CAFFE_SGD_SOLVERS_HPP_
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.12</a></td></tr>
  </table>
  <br>

</body>
</html>
